package com.example.android.apis;

import java.util.ArrayList;
import java.util.List;
import android.content.Context;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Adapter;
import android.widget.BaseAdapter;

public class NewsAdapter extends BaseAdapter{

	private Context context;
	public ArrayList<? extends News> list;
	private int selectedPosition;
	
	public NewsAdapter(Context context, ArrayList<? extends News> list)
	{
		this.context = context;
		this.list = list;
		selectedPosition = Adapter.NO_SELECTION;
		
	}
	
	public synchronized int getCount() {
		// TODO Auto-generated method stub
		return list.size();
	}

	public synchronized Object getItem(int arg0) {
		// TODO Auto-generated method stub
		return list.get(arg0);
	}

	public synchronized long getItemId(int arg0) {
		// TODO Auto-generated method stub
		return selectedPosition;
	}

public synchronized View getView(int position, View convertView, ViewGroup parent) {

	
		if (convertView == null)
		{
			NewsView temp = new NewsView(context,list.get(position));
			return temp;
		}
		
		else{
			
			((NewsView) convertView).setNews(list.get(position));
			return convertView;
		}
	}

}
